package modele;

import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;

//234|Ford|Fiesta|2004|10000|5345|12
//456|Renault|Clio|2001|150000|2300|5

public class Vehicule {
	
	private int id;
	private String marque;
	private String modele;
	private int annee;
	private int kilometrage;
	private double prix;
	private int nbExemplaire;
	
	
	public Vehicule(){
		super();
	}
	
	public Vehicule(int id, String marque, String modele, int annee,
			int kilometrage, double prix, int nbExemplaire) {
		super();
		this.id = id;
		this.marque = marque;
		this.modele = modele;
		this.annee = annee;
		this.kilometrage = kilometrage;
		this.prix = prix;
		this.nbExemplaire = nbExemplaire;
	}
	
	public String getMarque() {
		return marque;
	}
	public void setMarque(String marque) {
		this.marque = marque;
	}
	public String getModele() {
		return modele;
	}
	public void setModele(String modele) {
		this.modele = modele;
	}
	public int getAnnee() {
		return annee;
	}
	public void setAnnee(int annee) {
		this.annee = annee;
	}
	public int getKilometrage() {
		return kilometrage;
	}
	public void setKilometrage(int kilometrage) {
		this.kilometrage = kilometrage;
	}
	public double getPrix() {
		return prix;
	}
	public void setPrix(double prix) {
		this.prix = prix;
	}
	public int getNbExemplaire() {
		return nbExemplaire;
	}
	public void setNbExemplaire(int nbExemplaire) {
		this.nbExemplaire = nbExemplaire;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
	@Override
	public String toString()
	{
		return id +"|" + marque + "|" + modele + "|" + annee +"|"+ kilometrage +"|" + prix +"|" +nbExemplaire;
	}

	public void readData(Scanner in){
			try
		    {
				String line = in.nextLine() ;
				String[] tokens = line.split("\\|");
		        this.setId(Integer.parseInt(tokens[0]));
		        this.setMarque(tokens[1]);
		        this.setModele(tokens[2]);
		        this.setAnnee(Integer.parseInt(tokens[3]));
		        this.setKilometrage(Integer.parseInt(tokens[4]));
		       	this.setPrix(Double.parseDouble(tokens[5]));
		        this.setNbExemplaire(Integer.parseInt(tokens[6]));
		        System.out.println(this.toString());    
		    }
		    catch (NoSuchElementException exception){
		        System.out.println("Exception" + exception.getMessage());
		    }	 
	}
	public void writeData(PrintWriter out){
		try
		{
			out.print("\n"+this.toString());
			
		}
		catch (NoSuchElementException exception){
		        System.out.println("Exception" + exception.getMessage());
		}
	}

	@Override
	public boolean equals(Object obj)
	{
		boolean res=false;
		if (this == obj){
			res = true;
		}
		else if(this.getClass().equals(obj.getClass())){
			Vehicule autre = (Vehicule)obj;
			if((this.marque.equals(autre.marque))&&(this.modele.equals(autre.modele))){
				res=true;
			}
		}
		return res;
	}
	
}

